﻿package mortal.game.view.mainUI.avatar
{
    import com.gengine.global.*;
    import com.mui.utils.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.roleAvatar.*;

    public class EntityAvatar extends BaseAvater
    {
        protected var _buffPanel:BuffPanel;

        public function EntityAvatar()
        {
            return;
        }// end function

        override protected function configUI() : void
        {
            super.configUI();
            this.mouseEnabled = true;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.addBuff();
            return;
        }// end function

        override protected function addLevel() : void
        {
            var _loc_1:* = GlobalStyle.textFormatHui;
            _loc_1.size = 12;
            _loc_1.color = GlobalStyle.colorHuangUint;
            _loc_1.align = TextFormatAlign.CENTER;
            _level = UIFactory.gTextField("", 38, 53, 50, 50, this, _loc_1, false);
            return;
        }// end function

        override protected function addAvatar() : void
        {
            _avatar = UIFactory.gImageBitmap("", 20, 22, this);
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.AvatarMonsterlvBg, 48, 50, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.AvatarCircle, 16, 25, this));
            return;
        }// end function

        override protected function addLifeBar() : void
        {
            _shengmingBar = UICompomentPool.getUICompoment(BaseProgressBar);
            _shengmingBar.setProgress(ImagesConst.AvatarMonsterLife, false, 2, 0, 152, 12);
            _shengmingBar.setTweenProgress(ImagesConst.AvatarMonsterLifeTween, false, 2, 0, 152, 12);
            _shengmingBar.isCacheBmp = true;
            if (Global.isDebugModle)
            {
                _shengmingBar.setLabel(BaseProgressBar.ProgressBarTextOver, -35, -5);
            }
            else
            {
                _shengmingBar.setLabel(BaseProgressBar.ProgressBarTextPercent, -40, -5);
            }
            _shengmingBar.mouseChildren = false;
            _shengmingBar.mouseEnabled = true;
            _shengmingBar.x = 63;
            _shengmingBar.y = 25;
            this.addChild(_shengmingBar);
            return;
        }// end function

        protected function addBuff() : void
        {
            this._buffPanel = UICompomentPool.getUICompoment(BuffPanel);
            this._buffPanel.createDisposedChildren();
            this._buffPanel.x = 80;
            this._buffPanel.y = 60;
            this.addChild(this._buffPanel);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._buffPanel.dispose(param1);
            this._buffPanel = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function updateAvatar() : void
        {
            var _loc_1:BossInfo = null;
            if (_entityInfo && _entityInfo.entityInfo)
            {
                _avatar.bitmapData = null;
                _loc_1 = BossConfig.instance.getInfoByCode(_entityInfo.entityInfo.code);
                if (_loc_1)
                {
                    _avatar.imgUrl = _loc_1.avatarId + ".png";
                }
            }
            return;
        }// end function

        public function updateBufferByBuffInfoArray(param1:Array) : void
        {
            this._buffPanel.updateSelfeBuffer(param1);
            return;
        }// end function

        public function updateEntityBuffer(event:Event = null) : void
        {
            if (!_entityInfo)
            {
                return;
            }
            var _loc_2:* = _entityInfo.entityInfo.buffInfos;
            this._buffPanel.updateEntityBuffer(_entityInfo.entityInfo.buffInfos);
            return;
        }// end function

        override public function updateLevel(event:Event = null) : void
        {
            if (!_entityInfo)
            {
                return;
            }
            _level.text = _entityInfo.entityInfo.level.toString();
            return;
        }// end function

        override public function updateEntity(param1:EntityInfo) : void
        {
            super.updateEntity(param1);
            _shengmingBar.drawBar();
            this.updateEntityBuffer();
            return;
        }// end function

        override protected function addEntityEvent() : void
        {
            super.addEntityEvent();
            if (_entityInfo)
            {
                _entityInfo.addEventListener(EntityInfoEventName.UpdateBuffs, this.updateEntityBuffer);
            }
            return;
        }// end function

        override protected function removeEntityEvent(event:EntityInfoEvent = null) : void
        {
            super.removeEntityEvent();
            if (_entityInfo)
            {
                _entityInfo.removeEventListener(EntityInfoEventName.UpdateBuffs, this.updateEntityBuffer);
            }
            if (this._buffPanel)
            {
                this._buffPanel.clean();
            }
            return;
        }// end function

    }
}
